home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / WRAP.C < prev   
C/C++ Source or Header  |  1990-10-22  |  1KB  |  48 lines

  1. /*********
  2. * WRAP.C
  3. *
  4. * by Tom Rettig
  5. *
  6. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. *
  8. *  Syntax: WRAP( <expC>, <max len> )
  9. *  Return: <expN> position of last space less than or equal to <max len>,
  10. *             or position of last char in <expC> if less than <max len>.
  11. *             Returns <max len> of word and breaks the rest
  12. *             to the next line.
  13. *  Note..: Hyphens are not included so as not to cause a wrap on
  14. *          a negative number like -100.
  15. *********/
  16.  
  17. #include "trlib.h"
  18.  
  19. TRTYPE wrap()
  20. {
  21.    char *instr;
  22.    int end, too_long;
  23.  
  24.    if ( PCOUNT==2 && ISCHAR(1) && ISNUM(2) )
  25.    {
  26.       instr = _parc(1);
  27.       end = too_long  = _parni(2);
  28.  
  29.       if (end <= 0)
  30.          {
  31.             _retni( ERROR );   /* 0 error value */
  32.             return;
  33.          }
  34.  
  35.       if ( _tr_strlen(instr) > end )
  36.       {
  37.          while ( instr[end] != SPACEC )
  38.             end--;
  39.          _retni( (end >= 0) ? end : too_long );
  40.       }
  41.       else
  42.          _retni( _tr_strlen(instr) );
  43.    }
  44.    else
  45.       _retni( ERROR );   /* 0 error value */
  46. }
  47.  
  48.